#include <bits/stdc++.h>
// 2025/07/16
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, ans, t[100001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> t[i];
    sort(t + 1, t + n + 1);
    while (n > 3){
        ans += min(t[1] * 2 + t[n] + t[n - 1], t[1] + t[2] * 2 + t[n]);
        n -= 2;
    }
    if (n == 3)
        ans += t[1] + t[2] + t[3];
    else if (n == 2)
        ans += t[2];
    cout << ans << endl;
    return 0;
}